﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using ThresholdAssistant.DataContract.Result;
using ThresholdAssistant.WebAPI.Models;
using ThresholdAssistant.WebAPI.Service;

namespace ThresholdAssistant.WebAPI.Controllers
{
    /// <summary>
    /// 短信控制器
    /// </summary>
    [Route("api/sms")]
    public class SMSController : BaseController
    {
        /// <summary>
        /// 阿里云短信服务
        /// </summary>
        public AliyunSmsService AliyunSmsService { get; set; }

        /// <summary>
        /// 互亿短信服务
        /// </summary>
        public HuyiSmsService HuyiSmsService { get; set; }

        /// <summary>
        /// 发送模版消息
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost("send")]
        [AllowAnonymous]
        public async Task<ContractResult> SendSmsAsync(SendSmsParam param)
        {
            return await HuyiSmsService.SendSmsAsync(param);
        }

        /// <summary>
        /// 获取短信余量
        /// </summary>
        /// <returns></returns>
        [HttpPost("get-num")]
        [AllowAnonymous]
        public async Task<ContractResult<int>> GetNumAsync()
        {
            return await HuyiSmsService.GetSmsNumAsync();
        }

        /// <summary>
        /// 短信发送统计
        /// </summary>
        /// <returns></returns>
        [HttpPost("get-statistics")]
        [AllowAnonymous]
        public async Task<ContractResult<SmsStatisticsData>> GetStatisticsAsync(GetStatisticsParam param)
        {
            return await HuyiSmsService.GetStatisticsAsync(param);
        }

        /// <summary>
        /// 发送语音消息
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost("send-voice")]
        [AllowAnonymous]
        public async Task<ContractResult> SendVoiceAsync(SmsInfoParam param)
        {
            return await HuyiSmsService.SendVoiceAsync(param);
        }


        /// <summary>
        /// 获取语音余量
        /// </summary>
        /// <returns></returns>
        [HttpPost("get-voice-num")]
        [AllowAnonymous]
        public async Task<ContractResult<int>> GetVoiceNumAsync()
        {
            return await HuyiSmsService.GetVoiceNumAsync();
        }
    }
}